package edu.ucla.whi.wanda;

import java.util.LinkedList;
import java.util.List;

import org.restlet.ext.wadl.ParameterInfo;
import org.restlet.ext.wadl.ParameterStyle;
import org.restlet.resource.Get;

public class SubjectEventsResource extends BaseItemListResource {
	public static final String path = "/subjects/{subjectId}/events";
	public static final String description = "Get a list of events for a particular Subject";
	public static final String outputParamName = "EventList";
	
	
	public SubjectEventsResource() {
		super("subjectId");
		
		initDescribe(path, description, outputParamName);
	}
	
	@Override
	protected List<ParameterInfo> getParams() {
		List<ParameterInfo> params = new LinkedList<ParameterInfo>();
		
		// optional
		params.add(new ParameterInfo("order", false, "xsd:string", ParameterStyle.QUERY, 
				"ORDER BY clause used in select"));
		params.add(new ParameterInfo("next", false, "xsd:string", ParameterStyle.QUERY, 
				"Next token used in select"));
		
		return params;
	}
	
	@Override
	protected List<ParameterInfo> outputParams() {
		List<ParameterInfo> params = super.outputParams();
		
		params.add(0, newArrayParameterInfo("events", true, "xsd:string", ParameterStyle.PLAIN, 
				"A list of Event objects"));
		
		return params;
	}	
	
	@Get("json")
	public String list() {
		String where = "EventId = '" + itemId + "'";
		String order = params.get("order");
		String next = params.get("next");
		return BaseListResource.getList("events", EVENTS_DOMAIN, where, order, next).toString();
	}
}